<template>
  <div style="height:100%;width:100%;position:relative;overflow: hidden;">
      <div class="page-top" style="border:1px solid #CCC">
          <div style="min-width: 885px;">
              <div>
                  <table style="white-space: nowrap;">
                      <tr>
                          <td style="text-align:right">接收日期</td>
                          <td>
                              <el-date-picker type="date" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false" style="width: 130px" v-model="searchObj.startdt" key="1"></el-date-picker>
                          </td>
                          <td>至</td>
                          <td>
                              <el-date-picker type="date" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false" style="width: 130px" v-model="searchObj.enddt" key="2"></el-date-picker>
                          </td>
                          <td style="text-align:right">检验组</td>
                          <td>
                              <rm-ddl-common datatype="labgroup" dataname="检验组" v-model="searchObj.labgroupid" width="130px" @change="labgroupidChange"></rm-ddl-common>
                          </td>
                            <td style="text-align:right">姓&nbsp;名</td>
                          <td>
                              <el-input v-model="searchObj.patname" @keyup.enter.native="BtnQuery" clearable style="width:130px" placeholder=""></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:right">条形码</td>
                          <td colspan="3">
                              <el-input v-model="searchObj.barcode" @keyup.enter.native="BtnQuery" clearable style="width:100%" placeholder="输入条码号"></el-input>
                          </td>
                          <td style="text-align:right">病历号</td>
                          <td >
                              <el-input v-model="searchObj.patno" @keyup.enter.native="BtnQuery" clearable style="width:130px" placeholder=""></el-input>
                          </td>
                      </tr>
                      <tr>
                          <td style="text-align:right">检验项目</td>
                          <td colspan="3">
                              <el-input v-model="searchObj.rptitemcodes" @keyup.enter.native="BtnQuery" clearable style="width:100%" placeholder="双击选择检验项目或输入项目代码" @dblclick.native="bDlgRptItem=true"></el-input>
                          </td>
                          <td colspan="6">
                              <el-checkbox v-model="searchObj.bShowunrechk" true-label="1" false-label="0">仅显示未完成标本</el-checkbox>
                              <el-checkbox v-model="searchObj.bShowTest" true-label="1" false-label="0">仅显示上机/检测标本</el-checkbox>
                          </td>
                      </tr>
                  </table>
                  <div class="top-deal">
                      <el-button icon="el-icon-search" type="primary" @click="BtnQuery" v-has="'PINQUERY'">查询</el-button>
                      <el-button icon="el-icon-close" @click="btnClear">清除</el-button>
                      <el-button icon="el-icon-download" @click="exportExcel">导出</el-button>
                  </div>
              </div>
          </div>
      </div>
      <div class="pagecenter">
          <div style="height:100%;width:100%;">
              <vxe-table show-overflow ref="lxTable" :data.sync="LeftList" height="auto" :loading="LeftLoading" :sort-config="{trigger: 'cell'}" :keyboard-local-config="keyLocalConfig" border size="mini" show-header-overflow highlight-current-row resizable stripe header-align="center" show-footer  :span-method="rowspanMethod">
                  <vxe-table-column field="recieve_dt" title="接收时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="barcode" title="条码号" width="90" sortable></vxe-table-column>
                  <vxe-table-column field="pat_name" title="姓名" width="60" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_sexname" title="性别" width="40" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_agestr" title="年龄" width="60" sortable></vxe-table-column>
                  <vxe-table-column field="pat_no" title="病历号" width="80" sortable></vxe-table-column>
                          <vxe-table-column field="emer_flagname" title="加急" width="50" sortable></vxe-table-column>
                  <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="220" show-overflow> </vxe-table-column>
                  <vxe-table-column field="result_str" sortable title="检测结果" width="80" show-overflow> </vxe-table-column>
                  <vxe-table-column field="result_unit" sortable title="单位" width="70" show-overflow></vxe-table-column>
                  <vxe-table-column field="result_ref" sortable title="参考值" width="100" show-overflow></vxe-table-column>
                  <vxe-table-column field="req_groupna" title="分单类别" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="specimen_name" title="标本类型" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="libstatusname" title="库位状态" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="workstatusname" title="报告状态" width="80"></vxe-table-column>
                  <vxe-table-column field="hospitalname" title="送检医院" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="labgroupname" title="检验组" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="sampledate" title="最后上机时间" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="rptunitname" title="最后上机报告单元" width="100" align="center"></vxe-table-column>
                  <vxe-table-column field="sampleno" title="最后上机标本号" width="100" align="center"></vxe-table-column>
                  <vxe-table-column field="req_wardnoname" title="申请科室" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="req_bedno" title="床号" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="pat_typecodename" title="病人来源" width="60"></vxe-table-column>
                  <vxe-table-column field="req_docnoname" title="申请医生" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="req_dt" title="申请时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="inlib_username" title="入库人" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="req_stat" title="状态" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="itemid" title="入库时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="create_dt" title="创建时间" width="120" align="center"></vxe-table-column>
                  <vxe-table-column field="create_username" title="创建人" width="60" align="center"></vxe-table-column>
                  <vxe-table-column field="pat_diag" title="临床诊断" width="100"></vxe-table-column>
                  <vxe-table-column field="reject_reason" title="剔回原因" width="80"></vxe-table-column>
                  <vxe-table-column field="recieve_username" title="接收人" width="60" sortable align="center"></vxe-table-column>
                  <vxe-table-column field="charge_flag" title="计价标志" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="pat_birth" title="生日" width="80" align="center" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
                  <vxe-table-column field="perform_deptname" title="执行科室" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="req_wardnoname" title="病区代码" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="reject_count" title="剔回次数" width="60"></vxe-table-column>
                  <vxe-table-column field="specimen_code" title="标本类型代码" width="90"></vxe-table-column>
                  <vxe-table-column field="req_groupid" title="分单类别ID" width="90" align="center"></vxe-table-column>
                  <vxe-table-column field="recieve1_dt" title="工作组签收时间" width="120"></vxe-table-column>
                  <vxe-table-column field="recieve1_username" title="工作组签收人" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="inlib_statusname" title="入库状态" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="library_id" title="所在库位ID" width="70" align="center"></vxe-table-column>
                  <vxe-table-column field="reqtypename" title="申请单类别" width="80" align="center"></vxe-table-column>
                  <vxe-table-column field="tube_color" title="试管颜色" width="80"></vxe-table-column>
                  <vxe-table-column field="idhead" title="号段" width="60"></vxe-table-column>
                  <vxe-table-column field="idnumber" title="序号" width="60"></vxe-table-column>
              </vxe-table>
          </div>
      </div>
      <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择报告项目" :visible.sync="bDlgRptItem">
                 <rm-pop-selrptitem @cancel="bDlgRptItem=false;" @selitem="addrptitem"></rm-pop-selrptitem>
      </el-dialog>
  </div>
</template>

<script>
import XEUtils from "xe-utils"; //引入工具类
export default {
  name: "LIS353",
  data() {
      return {
          searchObj: {
              startdt: this.$pub.InitDateTime2(7).datefrom,
              enddt: this.$pub.InitDateTime2(7).dateto,
              labgroupid: "",
              barcode: "",
              rptitemcodes: "",

              patname: "",
              libheader: "",
              patno: "",
              status: 1,
              bShowunrechk:"0",
              bShowTest:"0",
          },
          LeftList: [],
          LeftLoading: false,
          RightList: [],
          RightLoading: false,
          keyLocalConfig: {
              isArrow: true,
          },
          bDlgRptItem: false,
          selectConfig: { tigger: "row", checkAll: true },
          userno: this.$tool.getSession(this.$tool.loginuserno),
          labgroupname: "",
          rptitemnames: "",
      };
  },
  created() {
  },
  methods: {
      addrptitem(rptitemcodeinfos) {
         this.searchObj.rptitemcodes = "";
         this.rptitemnames = "";
          for (var i = 0; i < rptitemcodeinfos.length; i++) {
              if ( this.searchObj.rptitemcodes == "") {
                 this.searchObj.rptitemcodes = rptitemcodeinfos[i].rpt_itemcode;
                 this.rptitemnames = rptitemcodeinfos[i].rpt_itemname;
              } else {
                  this.searchObj.rptitemcodes += "," + rptitemcodeinfos[i].rpt_itemcode;
                  this.rptitemnames += "," + rptitemcodeinfos[i].rpt_itemname;
              }
          }
          this.bDlgRptItem = false;
      },
       rowspanMethod ({ row, $rowIndex, column, data }) {
            let fields = ['recieve_dt','barcode','pat_name','pat_sexname','pat_agestr','pat_no'];
            let cellValue = row[column.property]
            if (cellValue && fields.includes(column.property)) {
              let prevRow = data[$rowIndex - 1]
              let nextRow = data[$rowIndex + 1]
              if (prevRow && prevRow[column.property] === cellValue) {
                return { rowspan: 0, colspan: 0 }
              } else {
                let countRowspan = 1
                while (nextRow && nextRow[column.property] === cellValue) {
                  nextRow = data[++countRowspan + $rowIndex]
                }
                if (countRowspan > 1) {
                  return { rowspan: countRowspan, colspan: 1 }
                }
              }
            }
      },
      BtnQuery() {
          this.LeftLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS353",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "query",
                      ...this.searchObj,
                  },
              })
              .then((res) => {
                  console.log(res);
                  this.LeftLoading = false;
                  this.LeftList = res.data;
              })
              .catch((e) => {
                  this.$alert(e, "出错");
                  this.LeftLoading = false;
              });
      },
      exportExcel() {
          let tableColumn = this.$refs.lxTable.getColumns();
          let extableColumn = [];
          tableColumn.forEach((item) => {
              extableColumn.push({ title: item.title, field: item.property });
          });
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcel(this.LeftList, extableColumn, "LIS353 标本完成情况查询.xlsx", filtertxt);
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "接收日期:" + XEUtils.toDateString(this.searchObj.startdt, "yyyy-MM-dd HH:mm:ss") + "至" + XEUtils.toDateString(this.searchObj.enddt, "yyyy-MM-dd HH:mm:ss") + "; ";
          if(this.searchObj.labgroupid) filtertxt += "检验组:" + this.labgroupname + "; ";
          if(this.searchObj.patname) filtertxt += "姓名:" + this.searchObj.patname + "; ";
          if(this.searchObj.barcode) filtertxt += "条形码:" + this.searchObj.barcode + "; ";
          if(this.searchObj.patno) filtertxt += "病历号:" + this.searchObj.patno + "; ";
          if(this.searchObj.rptitemcodes) filtertxt += "检验项目:" + this.rptitemnames + "; ";
          if(this.searchObj.bShowunrechk == "1") filtertxt += "仅显示未完成标本; ";
          if(this.searchObj.bShowTest == "1") filtertxt += "仅显示上机/检测标本; ";
          return filtertxt;
      },
      labgroupidChange(code, name) {
          this.searchObj.labgroupid = code;
          this.labgroupname = name;
          this.BtnQuery();
      },
      btnClear() {
          this.searchObj = {
              startdt: this.$pub.InitDateTime2(7).datefrom,
              enddt: this.$pub.InitDateTime2(7).dateto,
              labgroupid: "",
              barcode: "",
              rptitemcodes: "",
              patname: "",
              libheader: "",
              patno: "",
              bShowunrechk:"0",
              bShowTest:"0",
          };
          this.LeftList = [];
          this.RightList = [];
      },
  },
};
</script>

<style scoped>
.page-top {
  width: 100%;
  height: 135px;
  border: 1px solid #ccc;
  position: absolute;
  font-size: 12px;
  padding: 5px 0;
  line-height: 24px;
  overflow-x: auto;
  overflow-x: overlay;
}
::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}
::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

.top-deal {
  text-align: right;
  margin-right: 5px;
}
.pagecenter {
  position: absolute;
  top: 140px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
/deep/ .vxe-table .vxe-body--column.col-blue {
  color: blue;
}
.mytable-style {
  height: 100%;
}
/deep/ .mytable-style .vxe-table--body-wrapper {
  height: calc(100% - 54px) !important;
}
/deep/.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
</style>